package com.qubuyer.repository.entitys

import android.text.SpannableStringBuilder
import android.text.Spanned
import android.text.style.AbsoluteSizeSpan
import android.text.style.StrikethroughSpan
import com.qubuyer.core.ext.format
import com.qubuyer.core.ext.sp
import java.io.Serializable
import java.math.RoundingMode
import java.text.DecimalFormat
import java.text.NumberFormat
import java.util.*

class HomeGoodEntity : Serializable {
    //商品ID
    var goods_id = 0

    //商品号
    var goods_sn: String? = null

    //商品名
    var goods_name: String? = null

    //点击数
    var click_count = 0

    //库存
    var store_count = 0

    //市场价
    var market_price: String? = null

    //本店价
    var shop_price: String? = null
    private var nice_shop_price: CharSequence? = null

    //关键字
    var keywords: String? = null

    //商品简单描述
    var goods_remark: String? = null

    //商品内容
    var goods_content: String? = null

    //商品图
    var original_img: String? = null

    //商品图片
    var goods_images: List<GoodImg>? = null

    //商品SKU模型
    var goods_sku_model: List<GoodSKUModel>? = null
    var key_value_list: List<GoodSKUKeyValue>? = null

    //销售量
    var sales_sum = 0

    //收藏量
    var collect_sumn = 0

    //是否收藏 0否1是
    var is_collect: String? = null

    //商品分类信息
    var goods_category: CategoryFirstEntity? = null

    //规格ID
    var item_id = 0
    var price = 0f

    //商品数量
    var goods_num = 0

    //每人限购
    var buy_limit = 0

    //开始时间
    var start_time: Long = 0

    //结束时间
    var end_time: Long = 0

    //商品属性
    var goods_attr: List<GoodsAttrEntity>? = null

    //商品参数
    var goods_param: List<GoodsAttrEntity>? = null

    //折让金
    var restrore_price: String? = null

    //出手价
    var diff_price = 0.0
    private var nice_diff_price: CharSequence? = null

    //商品预算折让金
    var restore: String? = null

    //折扣比率
    var dis_rebate = 0f

    //是否上架
    var is_on_sale = 0

    //商品视频地址
    var video_full_path: String? = null

    //商品折扣点数
    var discount_rebate = 0
    override fun equals(o: Any?): Boolean {
        if (this === o) return true
        if (o == null || javaClass != o.javaClass) return false
        val that = o as HomeGoodEntity
        return goods_id == that.goods_id && java.lang.Double.compare(that.diff_price, diff_price) == 0 &&
                goods_name == that.goods_name &&
                market_price == that.market_price &&
                shop_price == that.shop_price &&
                original_img == that.original_img &&
                restrore_price == that.restrore_price
    }

    override fun hashCode(): Int {
        return Objects.hash(goods_id, goods_name, market_price, shop_price, original_img, restrore_price, diff_price)
    }

    constructor() {}
    constructor(goods_name: String?) {
        this.goods_name = goods_name
    }

    val niceShopPrice: CharSequence?
        get() {
            if (nice_shop_price == null) {
                val sb = SpannableStringBuilder("¥$shop_price")
                sb.setSpan(StrikethroughSpan(), 1, sb.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
                nice_shop_price = sb
            }
            return nice_shop_price
        }

    val niceDiffPrice: CharSequence?
        get() {
            if (nice_diff_price == null) {
                val format: String = diff_price.format().toString()
                val sb = SpannableStringBuilder(format)
                val i = format.indexOf(".")
                if (i >= 0) {
                    sb.setSpan(AbsoluteSizeSpan(10.sp), i + 1, sb.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
                }
                nice_diff_price = sb
            }
            return nice_diff_price
        }
}